//
//  ReportViewController.m
//  Light
//

//  Created by 骁唐 on 15/10/22.
//  Copyright © 2015年 骁唐. All rights reserved.
//

#import "ReportViewController.h"
#import "ReportStyleOneTableViewCell.h"
#import "ReportStyleTwoTableViewCell.h"
#import "NetworkTool.h"
#import "AFNetworking.h"
#import "AppDelegate.h"
#import "UserConfig.h"
#import "UMSocial.h"
#import "Light-Bridging-Header.h"
#import "Masonry.h"
//宏定义cell的高度，第一个cell和最后一个cell的高度，以及之前使用的cell的高度
#define HEIGHT_CELL 200
#define HEIGHT_CELL_HEARD 190  //105 190
#define HEIGHT_CELL_BOTTOM 105
#define HEIGHT_CELL_OLD 210

@interface ReportViewController ()<UITableViewDelegate,UITableViewDataSource,ChartViewDelegate>

@property (assign,nonatomic) char * myTest;
@property (weak, nonatomic) IBOutlet UIView *noReportView;//空白页 无睡眠抱抱
@property (weak, nonatomic) IBOutlet UIImageView *backGround;//背景图片

@property (strong,nonatomic) NSMutableArray *sleepStyleArr;//睡眠状态

@property (assign,nonatomic) int  Num;//总行数
@property (strong,nonatomic) NSMutableArray *convert;//转变数组
@property (strong,nonatomic) NSMutableArray *timerConvert;//各段时间的数组
//总时间   如果后期需要饼状图显示，这边可以有用了，否则，然并卵
@property (assign,nonatomic) int  Num1;
@property (assign,nonatomic) int  Num2;
@property (assign,nonatomic) int  Num3;
@property (assign,nonatomic) int  Num4;
@property (assign,nonatomic) int  Num5;
@property (assign,nonatomic) int  Num6;//干扰


@property (assign,nonatomic) int myConvert;//数组当前数字
@property (assign,nonatomic) int currentHeight;//当前高度
@property (assign,nonatomic) NSInteger myInteger;//计算每个时间段的时长用的。


@property (assign,nonatomic) int currentSec;//当前时间秒数
@property (assign,nonatomic) int currentHour;//当前时间小时
@property (assign,nonatomic) int currentMinute;//当前时间分钟

@property (strong,nonatomic) NSMutableArray *hourMinuteArray;//各个阶段小时 分钟
@property (strong,nonatomic) NSMutableArray *timesArray;//各个阶段的时常；
@property (strong,nonatomic) NSMutableArray *timeMutableArr;//最新x轴数据内容
//图表
@property (nonatomic, strong) BarChartView *barChartView;

@property (nonatomic, strong) BarChartData *data;
@property (copy ,nonatomic) NSArray *xAxisTitleArray;
@property (copy ,nonatomic) NSArray *xValues;
@end

@implementation ReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sleepStyleArr = [NSMutableArray new];
    self.timesArray = [NSMutableArray new];
    //如果前6个数据如果不等于6,则替换为5。
    Byte byt6[1] = {0};
    byt6[0] = 0x06;
    NSData *dataSix = [NSData dataWithBytes:&byt6 length:sizeof(byt6)];
    Byte byt5[1] = {0};
    byt5[0] = 0x05;
    NSData *dataFive = [NSData dataWithBytes:&byt5 length:sizeof(byt5)];
    //计算修改的下标。（如果睡眠报告小于6，则长度设置为睡眠报告的长度，否则设置为6.）
    NSInteger indexLength = self.reprotData.length>=6?6:self.reprotData.length;
    for (int i = 0; i < indexLength; i++)
    {
        if (![[self.reprotData subdataWithRange:NSMakeRange(i, 1)] isEqualToData:dataSix])
        {
            [self.reprotData replaceBytesInRange:NSMakeRange(i, 1) withBytes:[dataFive bytes]];
        }
    }
    //    [self configTestData];//配置测试数据  测试使用
    
    if (self.reprotData.length == 0 || [TJJDefines isNull:self.reprotData])
    {//如果睡眠报告为0；
        self.reportTableView.hidden = YES;
        self.noReportView.hidden = NO;
    }
    else
    {//如果有睡眠报告，空白页隐藏
        self.noReportView.hidden = YES;
        self.reportTableView.hidden = NO;
    }
    if (self.Calendar == 0 )
    {//从主页进来的 判断改善和控制是否开启 日历进来为1。 主页进来为0;
        UserConfig * config = [UserConfig sharingUserConfig];
        self.sleepGaishan = [config isSleepImproveShow];
        self.dreamKongZhi = [config isDreamImproveShow];
    }
    else
    {//从日历近来的。不设置睡眠改善和梦境控制。  不用设置，在传数据之前就已经设置了。
        //        self.sleepGaishan = NO;//睡眠改善
        //        self.dreamKongZhi = NO;//梦境控制
        //        self.sleepGaishan = YES;  //测试用
        //        self.dreamKongZhi = YES;
        
    }
    char *test = (char *)[self.reprotData bytes];
    self.myTest = test;//睡眠报告数据
    // Do any additional setup after loading the view from its nib.
    NSLog(@"传入的DATA%@",self.reprotData);
    self.convert = [[NSMutableArray alloc] init];//添加一共需要输出的数组(需要处理的数据)
    [self.convert addObject:@"0"];//排除第0位
    //生成睡眠数据报告图表的数据处理
    _timeMutableArr = [NSMutableArray new];
    for (int i = 0; i < self.reprotData.length; i ++) {
        switch (self.myTest[i]) {
            case 1:
                [_timeMutableArr addObject:@"1"];
                break;
            case 2:
                [_timeMutableArr addObject:@"2"];
                break;
            case 3:
                [_timeMutableArr addObject:@"3"];
                break;
            case 4:
                [_timeMutableArr addObject:@"4"];
                break;
            case 5:
                [_timeMutableArr addObject:@"5"];
                break;
            case 6:
                [_timeMutableArr addObject:@"6"];
                break;
            default:
                break;
        }
    }
    //
    for (int i = 0 ; i < self.reprotData.length; i ++)
    {
        switch (self.myTest[i])
        {
            case 1:
                self.Num1 ++;
                if (self.myConvert != 1)
                {
                    [self.convert addObject:@"1"];
                    self.myConvert = 1;
                }
                break;
            case 2:
            case 3:
            {//将2和3合并，处理成3。
                self.Num3 ++;
                if (self.myConvert != 3)
                {
                    [self.convert addObject:@"3"];
                    self.myConvert = 3;
                }
                break;
            }
            case 4:
                self.Num4 ++;
                if (self.myConvert != 4)
                {
                    [self.convert addObject:@"4"];
                    self.myConvert = 4;
                }
                break;
            case 5:
                self.Num5 ++;
                if (self.myConvert != 5)
                {
                    [self.convert addObject:@"5"];
                    self.myConvert = 5;
                }
                break;
            case 6:
                self.Num6 ++;
                if (self.myConvert != 6)
                {
                    [self.convert addObject:@"6"];
                    self.myConvert = 6;
                }
                break;
            default:
                break;
        }
    }
    NSLog(@"加载的数组%@",self.convert);
    self.Num = (int)self.convert.count-1;//cell的个数统计。
    TJJLog(@"有cell--%d----行",self.Num);
    TJJLog(@"num1=%d---num3=%d--num4=%d--num5=%d---num6=%d---num2=%d",self.Num1,self.Num3,self.Num4,self.Num5,self.Num6,self.Num2);
    if (self.reprotData.length > 0)
    {
        [self CountCellNumber];//计算每个睡眠阶段数据的长度
        NSLog(@"加载的各位数的长度数组%@",self.timerConvert);
        //计算每个时间段的时间长度
        for (int i = 1; i < self.timerConvert.count; i++) {
            int a = [self.timerConvert[i] intValue]/2;
            [self.timesArray addObject:@(a)];
        }
        NSLog(@"self.timesArray = %@",self.timesArray);
        [self configCurrentTime];//算时间
    }
}


#pragma mark -
#pragma mark 配置测试数据
- (void)configTestData
{
    Byte byt6[1] = {0};
    byt6[0] = 0x06;
    NSData *dataSix = [NSData dataWithBytes:&byt6 length:sizeof(byt6)];
    
    Byte byt5[1] = {0};
    byt5[0] = 0x05;
    NSData *dataFive = [NSData dataWithBytes:&byt5 length:sizeof(byt5)];
    
    Byte byt4[1] = {0};
    byt4[0] = 0x04;
    NSData *dataFour = [NSData dataWithBytes:&byt4 length:sizeof(byt4)];
    
    Byte byt3[1] = {0};
    byt3[0] = 0x03;
    NSData *dataThree = [NSData dataWithBytes:&byt3 length:sizeof(byt3)];
    
    Byte byt2[1] = {0};
    byt2[0] = 0x02;
    NSData *dataTwo = [NSData dataWithBytes:&byt2 length:sizeof(byt2)];
    
    Byte byt1[1] = {0};
    byt1[0] = 0x01;
    NSData *dataOne = [NSData dataWithBytes:&byt1 length:sizeof(byt1)];
    
    //    [self.reprotData replaceBytesInRange:NSMakeRange(7, 1) withBytes:[dataOne bytes]];
    //    [self.reprotData replaceBytesInRange:NSMakeRange(8, 1) withBytes:[dataOne bytes]];
    //    [self.reprotData replaceBytesInRange:NSMakeRange(9, 1) withBytes:[dataOne bytes]];
    
    
    
    // 添加测试数据  TODO:打包上线去掉
    for (int i = 0; i < 6; i++)
    {
        [self.reprotData appendData:dataSix];//添加接触不良 6
    }
    for (int i = 0; i < 6; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataThree];//添加浅度度睡眠 3
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠 1
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠 1
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataSix];//添加接触不良  6
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataThree];//添加浅度度睡眠 3
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataThree];//添加浅度度睡眠 3
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataThree];//添加浅度度睡眠 3
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 100; i++)
    {
        [self.reprotData appendData:dataSix];//添加接触不良 6
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 100; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataOne];//添加深度睡眠  1
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataTwo];//添加浅度度睡眠 2
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 20; i++)
    {
        [self.reprotData appendData:dataThree];//添加浅度度睡眠 3
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 100; i++)
    {
        [self.reprotData appendData:dataSix];//添加接触不良 6
    }
    for (int i = 0; i < 30; i++)
    {
        [self.reprotData appendData:dataFour];//添加做梦 4
    }
    for (int i = 0; i < 10; i++)
    {
        [self.reprotData appendData:dataFive];//添加清醒 5
    }
}

#pragma mark -
#pragma mark 计算每个睡眠阶段数据的长度--统计的字符串的个数(合并2和3)
- (void)CountCellNumber
{//把2当做3来进行统计
    int nowNum = self.myTest[0];
    int indexPre;
    if (nowNum == 2)//将2替换成3
    {
        indexPre = 3;
    }
    else
    {
        indexPre = nowNum;
    }
    self.myInteger = 0;//初始化统计个数
    self.timerConvert = [[NSMutableArray alloc] init];
    [self.timerConvert addObject:@"zhanwei0"];//用来标记占位的，排除第0位
    
    for (int i = 0 ; i< self.reprotData.length; i ++)
    {
        if (self.myTest[i] == 2)
        {//因为2和3 都是浅睡，那么，将2替换成3
            nowNum = 3;
        }
        else
        {
            nowNum = self.myTest[i];//本身
        }
        
        if (!(nowNum == indexPre))//如果不相同
        {
            NSNumber *number = [NSNumber numberWithInt:(int)self.myInteger];
            [self.timerConvert addObject:number];//添加时间段长度
            //            NSLog(@"SXW---%lu个值：%d",self.myInteger,indexPre);
            indexPre =nowNum;
            self.myInteger = 1;//初始化为1.时间段初始化为1.
        }
        else
        {//如果相同  时长加上1.
            self.myInteger++;
        }
    }
    //    NSLog(@"SXW---%lu个值：%d",self.myInteger,indexPre);
    NSNumber *number = [NSNumber numberWithInt:(int)self.myInteger];
    [self.timerConvert addObject:number];//最后一个时长加入。
    //    NSLog(@"-----%lu个数据",self.timerConvert.count);
}

#pragma mark -
#pragma mark 算全部时间（这里计算的时间都是这个阶段结束的时间。）
-(void)configCurrentTime
{
    //清醒 当前时间
    NSString *currenTime = [[NSString alloc] init];
    if (self.Calendar == 1)
    {//日历进来为1。 主页进来为0;
        currenTime = self.clearTime;//传过来的时间。
    }
    else
    {//主页进来为0;
        UserConfig *config = [UserConfig sharingUserConfig];
        currenTime =[config getReportStartTime];//获取报告开始的时间
    }
    NSRange range = [currenTime rangeOfString:@":"];
    self.currentHour = [[currenTime substringToIndex:range.location] intValue];//时
    self.currentMinute  = [[currenTime substringFromIndex:range.location +1] intValue];//分
    
    int HourSec1 =  self.currentHour*3600;
    int MinuteSec1 = self.currentMinute*60;
    self.currentSec = HourSec1 + MinuteSec1;//秒
    self.hourMinuteArray = [[NSMutableArray alloc] init];
    [_hourMinuteArray addObject:currenTime];//第一个应该添加睡眠报告开始的时间。
    //+1
    for (int i =0 ; i < self.Num+1  ; i++)
    {
        switch ([self.convert[i] intValue])//对应的睡眠阶段
        {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            {//算时间
                int currentTimen1  = [self.timerConvert[i] intValue]*30;//对应的睡眠阶段
                int time1 = currentTimen1 + self.currentSec;
                self.currentSec = time1;
                if (time1 > 86400)
                {
                    time1 = time1 - 86400;
                }
                int hour = time1/3600;
                int minute = (time1%3600)/60;
                NSString * hourMinute = [[NSString alloc] initWithFormat:@"%d:%d",hour,minute];
                [_hourMinuteArray addObject:hourMinute];
            }
                break;
            default:
                break;
        }
    }
    NSLog(@"时间数组_hourMinuteArray%@",_hourMinuteArray);
    
    NSMutableArray *mutableArr = [NSMutableArray new];
    for (NSInteger i = 0 ; i < _hourMinuteArray.count ; i++) {
        [mutableArr addObject:[TJJDefines stringTimeDouble:_hourMinuteArray[i]]];
    }
    NSMutableArray *newArray1 = [NSMutableArray new];
    for (int i = 0 ; i < self.timesArray.count; i++) {
        [newArray1 addObject:mutableArr[i]];
        int times = [self.timesArray[i] intValue];
        for (int j = 0 ; j < times-1; j++) {
            [newArray1 addObject:@""];
        }
    }
    [newArray1 addObject:mutableArr[mutableArr.count-1]];
    
    NSLog(@"newArray  = %@",newArray1);
    _xAxisTitleArray = newArray1;
    int indexData;
    for (NSInteger i = 0; i < self.convert.count ; i++) {
        indexData  = [self.convert[i] intValue];
        switch (indexData) {
            case 1:
                [self.sleepStyleArr addObject:@"1"];
                break;
            case 2:
                [self.sleepStyleArr addObject:@"2"];
                break;
            case 3:
                [self.sleepStyleArr addObject:@"3"];
                break;
            case 4:
                [self.sleepStyleArr addObject:@"4"];
                break;
            case 5:
                [self.sleepStyleArr addObject:@"5"];
                break;
            case 6:
                [self.sleepStyleArr addObject:@"6"];
                break;
                
            default:
                break;
        }
    }
    
    NSMutableArray *newArray2 = [NSMutableArray new];
    for (int i = 0 ; i < self.timesArray.count; i++) {
        [newArray2 addObject:self.sleepStyleArr[i]];
        int times = [self.timesArray[i] intValue];
        for (int j = 0 ; j < times-1; j++) {
            [newArray2 addObject:self.sleepStyleArr[i]];
        }
    }
    [newArray2 addObject:self.sleepStyleArr[self.sleepStyleArr.count-1]];
    _xValues = newArray2;
    NSLog(@"self.sleepStyleArr  = %@",self.sleepStyleArr );
    //设置头视图的报表
    self.reportTableView.tableHeaderView = [self reportViewWithChart];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
- (UIView *)reportViewWithChart{
    
    UIView *chartView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH , 300)];
    //    chartView.backgroundColor = [UIColor colorWithRed:82/255.0 green:102/255.0 blue:156/255.0 alpha:1.0];
    //添加barChartView
    self.barChartView = [[BarChartView alloc] init];
    self.barChartView.backgroundColor=  [UIColor colorWithRed:82/255.0 green:102/255.0 blue:156/255.0 alpha:1.0];
    self.barChartView.delegate = self;//设置代理
    [self.view addSubview:self.barChartView];
    [self.barChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.view.bounds.size.width, 300));
        make.center.mas_equalTo(self.view);
    }];
    [chartView addSubview:self.barChartView];
    //基本样式
    self.barChartView.noDataText = @"暂无数据";//没有数据时的文字提示
    self.barChartView.drawValueAboveBarEnabled = YES;//数值显示在柱形的上面还是下面
    self.barChartView.drawHighlightArrowEnabled = NO;//点击柱形图是否显示箭头
    self.barChartView.drawBarShadowEnabled = NO;//是否绘制柱形的阴影背景
    
    //交互设置
    self.barChartView.scaleYEnabled = NO;//取消Y轴缩放
    self.barChartView.doubleTapToZoomEnabled = NO;//取消双击缩放
    self.barChartView.dragEnabled = YES;//启用拖拽图表
    self.barChartView.dragDecelerationEnabled = YES;//拖拽后是否有惯性效果
    self.barChartView.dragDecelerationFrictionCoef = 0.9;//拖拽后惯性效果的摩擦系数(0~1)，数值越小，惯性越不明显
    
    //X轴样式
    ChartXAxis *xAxis = self.barChartView.xAxis;
    xAxis.axisLineWidth = 1;//设置X轴线宽
    xAxis.labelPosition = XAxisLabelPositionBottom;//X轴的显示位置，默认是显示在上面的
    xAxis.drawGridLinesEnabled = NO;//不绘制网格线
    xAxis.spaceBetweenLabels = 2;//设置label间隔，若设置为1，则如果能全部显示，则每个柱形下面都会显示label
    xAxis.labelTextColor = [UIColor whiteColor];//label文字颜色
    
    //右边Y轴样式
    self.barChartView.rightAxis.enabled = NO;//不绘制右边轴
    
    //左边Y轴样式
    ChartYAxis *leftAxis = self.barChartView.leftAxis;//获取左边Y轴
    leftAxis.labelCount = 5;//Y轴label数量，数值不一定，如果forceLabelsEnabled等于YES, 则强制绘制制定数量的label, 但是可能不平均
    leftAxis.forceLabelsEnabled = NO;//不强制绘制制定数量的label
    leftAxis.showOnlyMinMaxEnabled = NO;//是否只显示最大值和最小值
    leftAxis.axisMinValue = 0;//设置Y轴的最小值
    leftAxis.startAtZeroEnabled = YES;//从0开始绘制
    leftAxis.axisMaxValue = 6;//设置Y轴的最大值
    leftAxis.inverted = NO;//是否将Y轴进行上下翻转
    leftAxis.axisLineWidth = 0.2;//Y轴线宽
    leftAxis.axisLineColor = [UIColor whiteColor];//Y轴颜色
    leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
    leftAxis.labelTextColor = [UIColor whiteColor];//文字颜色
    leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字体
    //网格线样式
    leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//设置虚线样式的网格线
    leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//网格线颜色
    leftAxis.gridAntialiasEnabled = YES;//开启抗锯齿
    
    //图例说明样式
    self.barChartView.legend.enabled = NO;//不显示图例说明
    //    self.barChartView.legend.position = ChartLegendPositionBelowChartLeft;//位置
    
    //右下角的description文字样式
    self.barChartView.descriptionText = @"";//不显示，就设为空字符串即可
    //    self.barChartView.descriptionText = @"柱形图";
    
    self.data = [self setData];
    
    //为柱形图提供数据
    self.barChartView.data = self.data;
    
    //设置动画效果，可以设置X轴和Y轴的动画效果
    [self.barChartView animateWithYAxisDuration:1.0f];
    
    
    return chartView;
}
//为柱形图设置数据
- (BarChartData *)setData{
    
    NSUInteger xVals_count = _xAxisTitleArray.count;//X轴上要显示多少条数据
    //X轴上面需要显示的数据
    NSMutableArray *xVals = [[NSMutableArray alloc] init];
    //对应Y轴上面需要显示的数据
    NSMutableArray *yVals = [[NSMutableArray alloc] init];
    for (int i = 0; i < xVals_count; i++) {
        [xVals addObject:_xAxisTitleArray[i]];
        
    }
    for (int i = 0; i < xVals_count-1; i++) {
        double val = [_xValues[i] doubleValue];
        BarChartDataEntry *entry = [[BarChartDataEntry alloc] initWithValue:val xIndex:i];
        [yVals addObject:entry];
    }
    //创建BarChartDataSet对象，其中包含有Y轴数据信息，以及可以设置柱形样式
    BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals label:nil];
    set1.barSpace = -0.024;//柱形之间的间隙占整个柱形(柱形+间隙)的比例
    set1.drawValuesEnabled = NO;//是否在柱形图上面显示数值
    set1.highlightEnabled = NO;//点击选中柱形图是否有高亮效果，（双击空白处取消选中）
    NSMutableArray *colorsArr = [[NSMutableArray alloc] init];
    UIColor *color = [[UIColor alloc] init];
    for (int i = 0; i < xVals_count-1; i++) {
        int xValues = [_xValues[i] intValue];
        switch (xValues) {
            case 6:
                color = [UIColor colorWithRed:170/255.0 green:170/255.0 blue:170/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            case 5:
                color = [UIColor colorWithRed:249/255.0 green:30/255.0 blue:109/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            case 4:
                color = [UIColor colorWithRed:253/255.0 green:189/255.0 blue:52/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            case 3:
                color = [UIColor colorWithRed:178/255.0 green:142/255.0 blue:233/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            case 2:
                color = [UIColor colorWithRed:115/255.0 green:85/255.0 blue:164/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            case 1:
                color = [UIColor colorWithRed:78/255.0 green:50/255.0 blue:124/255.0 alpha:1.0];
                [colorsArr addObject:color];
                break;
            default:
                break;
        }
    }
    [set1 setColors:colorsArr];//设置柱形图颜色
    //将BarChartDataSet对象放入数组中
    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [dataSets addObject:set1];
    
    //创建BarChartData对象, 此对象就是barChartView需要最终数据对象
    BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];//文字字体
    [data setValueTextColor:[UIColor whiteColor]];//文字颜色
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    //自定义数据显示格式
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    [formatter setPositiveFormat:@"#0.0"];
    [data setValueFormatter:formatter];
    
    return data;
}

#pragma mark - UITableViewDataSource

#pragma mark section的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark -
#pragma mark cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.Num+1;//一个结尾（因为开始已经展示了一个数据，所以这边只增加一个。）
}

#pragma mark -
#pragma mark cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"当前的行数%ld",(long)indexPath.row);
    
    if (indexPath.row == self.Num)
    {//最后一行
        return HEIGHT_CELL_BOTTOM;
    }
    else
    {
        switch ([self.convert[indexPath.row] intValue])
        {
            case 0:
            {//头部
                self.currentHeight = HEIGHT_CELL_HEARD;//190  110
                return HEIGHT_CELL_HEARD;//190
            }
                break;
            case 1:
            {//深睡
                //睡眠改善关闭
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            case 2:
            {//轻睡
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            case 3:
            {//浅睡
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            case 4:
            {//做梦
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            case 5:
            {//清醒
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            case 6:
            {//接触不良  130
                self.currentHeight = HEIGHT_CELL;
                return self.currentHeight;
            }
                break;
            default:
                break;
        }
    }
    
    return self.currentHeight;
}

//半透明
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//    UIColor *altCellColor = [UIColor colorWithWhite:1.0 alpha:0.6];
//
//    cell.backgroundColor = altCellColor;
//    altCellColor = [UIColor colorWithWhite:1.0 alpha:0.0];
//    cell.textLabel.backgroundColor = altCellColor;
//    cell.detailTextLabel.backgroundColor = altCellColor;
//}
#pragma mark -
#pragma mark celld定义
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"进来%ld",(long)indexPath.row);
    static NSString *identifier = @"reportOneID";
    static NSString *identifierTwo = @"reportTwoID";
    
    ReportStyleTwoTableViewCell *cellTwo = [tableView dequeueReusableCellWithIdentifier:identifierTwo];
    if (nil == cellTwo)
    {
        UINib *nibTwo = [UINib nibWithNibName:@"ReportStyleTwoTableViewCell" bundle:nil];
        [_reportTableView registerNib:nibTwo forCellReuseIdentifier:identifierTwo];
        cellTwo =[[[NSBundle mainBundle]loadNibNamed:@"ReportStyleTwoTableViewCell" owner:nil options:nil] lastObject];
    }
    
    cellTwo.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSLog(@"当前的行数%ld",(long)indexPath.row);
    
    if (indexPath.row == self.Num)
    {//结束 最末尾的
        UINib *nib = [UINib nibWithNibName:@"ReportStyleOneTableViewCell" bundle:nil];
        [_reportTableView registerNib:nib forCellReuseIdentifier:identifier];
        ReportStyleOneTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];//cellOne,开始的时候
        if (nil == cellOne)
        {
            cellOne = [[[NSBundle mainBundle]loadNibNamed:@"ReportStyleOneTableViewCell" owner:nil options:nil] lastObject];
        }
        cellOne.selectionStyle = UITableViewCellSelectionStyleNone;//点击不可选
        NSString * startDateString = [NSString stringWithFormat:@"结束睡眠"];
        CGSize size = [startDateString sizeWithFont:cellOne.currentDate.font constrainedToSize:CGSizeMake(SCREEN_WIDTH-40, 10) lineBreakMode:NSLineBreakByCharWrapping];//计算展示内容的宽度
        cellOne.widthViewDateTitle.constant = (float)(size.width+10.0);//改变view的width
        cellOne.currentDate.text = startDateString;//显示睡眠开始时间。
        [cellOne.contentView layoutIfNeeded];
        //隐藏其他没有用到的控件
        cellOne.labelState.hidden = YES;
        cellOne.imageViewOne.hidden = YES;
        cellOne.imageViewTwo.hidden = YES;
        
        return cellOne;
    }
    else
    {//开始，或者其他状态
        int indexData = [self.convert[indexPath.row] intValue];
        if (indexData != 0)
        {//如果不是开头，那么就需要跳过开头的一个，因为开头0 已经取值了第一个数据，进行了展示。
            indexData = [self.convert[indexPath.row+1] intValue];//如果不是开头，那么以后每个cell的值都需要跳过一个
        }
        switch (indexData)
        {
            case 0:
            {
                UINib *nib = [UINib nibWithNibName:@"ReportStyleOneTableViewCell" bundle:nil];
                [_reportTableView registerNib:nib forCellReuseIdentifier:identifier];
                ReportStyleOneTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];//cellOne,开始的时候
                if (!cellOne)
                {
                    cellOne = [[[NSBundle mainBundle]loadNibNamed:@"ReportStyleOneTableViewCell" owner:nil options:nil] lastObject];
                }
                cellOne.selectionStyle = UITableViewCellSelectionStyleNone;//点击不可选
                NSString *currenTime = [[NSString alloc] init];
                cellOne.labelState.hidden = NO;//隐藏第一个信息展示
                cellOne.imageViewOne.hidden = NO;
                cellOne.imageViewTwo.hidden = NO;//隐藏第二个下拉
                //清醒 当前时间
                if (self.Calendar == 1)//判断是不是从日历进入，日历进来为1。 主页进来为0;
                {//日历进来为1。
                    currenTime = self.clearTime;//这个值是日历那边传过来的。
                }
                else
                {//主页为0
                    UserConfig *config = [UserConfig sharingUserConfig];
                    currenTime =[config getReportStartTime];
                }
                
                NSRange range = [currenTime rangeOfString:@":"];
                self.currentHour = [[currenTime substringToIndex:range.location] intValue];
                self.currentMinute  = [[currenTime substringFromIndex:range.location + 1] intValue];
                int HourSec1 =  self.currentHour*3600;
                int MinuteSec1 = self.currentMinute*60;
                self.currentSec = HourSec1 + MinuteSec1;
                //需要设置第一个时间段。
                //            cellOne.currentLabel.text = [NSString stringWithFormat:@"清醒时长 0小时0分"];//暂时隐藏不用
                NSString * stringTime = [NSString stringWithFormat:@"%d:%d",self.currentHour,self.currentMinute];
                NSLog(@"stringTime = %@",stringTime);
                //从日历传入的时候显示日期   日历进来为1。 主页进来为0;
                if (self.Calendar == 1)
                {//开始时间展示
                    NSString * startDateString = [NSString stringWithFormat:@"开始睡眠 %@ %@",self.currentDate,[TJJDefines stringTimeDouble:stringTime]];
                    CGSize size = [startDateString sizeWithFont:cellOne.currentDate.font constrainedToSize:CGSizeMake(SCREEN_WIDTH-40, 10) lineBreakMode:NSLineBreakByCharWrapping];//计算展示内容的宽度
                    cellOne.widthViewDateTitle.constant = (float)(size.width+10.0);//改变view的width
                    cellOne.currentDate.text = startDateString;//显示睡眠开始时间。
                    [cellOne.contentView layoutIfNeeded];
                }
                else
                {//开始时间不修改。默认“今天”
                    NSString * startDateString = [NSString stringWithFormat:@"开始睡眠 %@",[TJJDefines stringTimeDouble:stringTime]];
                    CGSize size = [startDateString sizeWithFont:cellOne.currentDate.font constrainedToSize:CGSizeMake(SCREEN_WIDTH-40, 10) lineBreakMode:NSLineBreakByCharWrapping];//计算展示内容的宽度
                    cellOne.widthViewDateTitle.constant = (float)(size.width+10.0);//改变view的width
                    cellOne.currentDate.text = startDateString;//显示睡眠开始时间。
                    [cellOne.contentView layoutIfNeeded];
                }
                
                //第一个阶段展示的阶段长度
                int indexDataValue = [self.convert[indexPath.row+1] intValue];//获取这是哪个状态的。
                NSMutableString * stringHeader = [[NSMutableString alloc] initWithCapacity:0];//存储头部字符串，需要根据判断进行设置
                switch (indexDataValue)
                {
                    case 1://深度睡眠
                    {
                        [stringHeader appendString:@"深度睡眠时长 "];
                    }
                        break;
                    case 2://浅度睡眠
                    {
                        [stringHeader appendString:@"浅度睡眠时长 "];
                    }
                        break;
                    case 3://浅度睡眠
                    {
                        [stringHeader appendString:@"浅度睡眠时长 "];
                    }
                        break;
                    case 4://做梦
                    {
                        [stringHeader appendString:@"做梦时长 "];
                    }
                        break;
                    case 5://清醒
                    {
                        [stringHeader appendString:@"清醒时长 "];
                    }
                        break;
                    case 6://接触不良
                    {
                        [stringHeader appendString:@"接触不良时长 "];
                    }
                        break;
                        
                    default:
                    {
                        [stringHeader appendString:@"未知时长 "];
                    }
                        break;
                }
                TJJLog(@"第0行");
                
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellOne.currentLabel.text = [NSString stringWithFormat:@"%@%d小时%.1f分",stringHeader,hour,floatMin];//显示第一个数据的
                return cellOne;
            }
                break;
            case 1:
            {//深度睡眠
                [_sleepStyleArr addObject:@"800"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                //其他内容展示
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_ONE];
                cellTwo.assessView.hidden = NO;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                cellTwo.oneXiala.hidden = NO;
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                if(floatMin>20)
                {
                    cellTwo.assessLabel.text = @"优秀";
                }
                else if(floatMin<=20&&floatMin>10)
                {
                    cellTwo.assessLabel.text = @"良好";
                }
                else
                {
                    cellTwo.assessLabel.text = @"加油";
                }
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"深度睡眠时长 %d小时%.1f分",hour,floatMin];
                
                //计算进入睡眠的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 4)
                {// 如果前一个 阶段不是 做梦  模式二 隐藏
                    cellTwo.viewStatusTwo.hidden = YES;// 模式二 隐藏
                    if (self.sleepGaishan == YES)
                    {//睡眠改善开启
                        cellTwo.sleepView.hidden = NO;//模式一 打开
                        cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_ON; //显示 睡眠改善开启
                        cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                    }
                    else
                    {//睡眠改善关闭
                        cellTwo.sleepView.hidden = YES; // 模式一 隐藏
                    }
                }
                else
                {//如果前一个是 做梦阶段
                    if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                    {//如果梦境控制开启  并且 睡眠时间大于5小时
                        if (self.sleepGaishan == YES)
                        {//睡眠改善开启
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_ON;//显示 睡眠改善开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                            cellTwo.viewStatusTwo.hidden = NO;// 模式二 打开
                            cellTwo.labelTitleStatusTwo.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制关闭
                            cellTwo.imageViewBackGroundTwo.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {//睡眠改善关闭
                            cellTwo.viewStatusTwo.hidden = YES;// 模式二 隐藏
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制关闭
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                    }
                    else
                    {//梦境控制关闭 或者 睡眠时间小于5小时
                        cellTwo.viewStatusTwo.hidden = YES;// 模式二 隐藏
                        if (self.sleepGaishan == YES)
                        {//睡眠改善开启
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_ON;//显示 睡眠改善开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {//睡眠改善关闭
                            cellTwo.sleepView.hidden = YES;//模式一 隐藏
                        }
                    }
                }
                return cellTwo;
            }
                break;
            case 2:
            {//浅度睡眠，如果不出差，这里将不会出现，因为2都转成3处理了。
                [_sleepStyleArr addObject:@"600"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_THREE];
                cellTwo.assessView.hidden = YES;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"浅度睡眠时长 %d小时%.1f分",hour,floatMin];
                cellTwo.oneXiala.hidden = NO;
                //计算进入睡眠的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 4 && priData != 1)
                {//如果前一个不是 1 和不是4   隐藏 模式二和模式一
                    cellTwo.viewStatusTwo.hidden = YES;  //模式二 隐藏
                    cellTwo.sleepView.hidden = YES;  // 模式一 隐藏
                }
                else
                {//模式二 隐藏
                    cellTwo.viewStatusTwo.hidden = YES; // 模式二 隐藏
                    if (priData == 1)
                    {// 如果前一个是 深度睡眠
                        if (self.sleepGaishan)
                        {// 如果睡眠改善开启
                            cellTwo.sleepView.hidden = NO; //模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_OFF;//睡眠改善关闭
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果睡眠改善关闭
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else if (priData == 4)
                    {// 如果前一个是 做梦
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {// 如果梦境控制开启  并且 睡眠时间在5个小时以上
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果不符合 梦境控制开启， 或者不符合睡眠时间长度大于5小时以上的，需要隐藏 模式一
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else
                    {//其他错误  模式一 隐藏
                        cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                    }
                }
                return cellTwo;
            }
                break;
            case 3:
            {//浅度睡眠
                [_sleepStyleArr addObject:@"600"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_THREE];
                cellTwo.assessView.hidden = YES;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"浅度睡眠时长 %d小时%.1f分",hour,floatMin];
                cellTwo.oneXiala.hidden = NO;
                
                //计算进入睡眠的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 4 && priData != 1)
                {//如果前一个不是 1 和不是4   隐藏 模式二和模式一
                    cellTwo.viewStatusTwo.hidden = YES;  //模式二 隐藏
                    cellTwo.sleepView.hidden = YES;  // 模式一 隐藏
                }
                else
                {//模式二 隐藏
                    cellTwo.viewStatusTwo.hidden = YES; // 模式二 隐藏
                    if (priData == 1)
                    {// 如果前一个是 深度睡眠
                        if (self.sleepGaishan)
                        {// 如果睡眠改善开启
                            cellTwo.sleepView.hidden = NO; //模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果睡眠改善关闭
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else if (priData == 4)
                    {// 如果前一个是 做梦
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {// 如果梦境控制开启  并且 睡眠时间在5个小时以上
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果不符合 梦境控制开启， 或者不符合睡眠时间长度大于5小时以上的，需要隐藏 模式一
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else
                    {//其他错误  模式一 隐藏
                        cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                    }
                }
                
                return cellTwo;
            }
                break;
            case 4:
            {//做梦
                [_sleepStyleArr addObject:@"400"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                //计算进入深度睡眠之后的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                
                //设置其他内容
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_FOUR];
                cellTwo.assessView.hidden = YES;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"做梦时长 %d小时%.1f分",hour,floatMin];
                cellTwo.oneXiala.hidden = NO;
                
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 1)
                {//如果前一个不是 1  不是深度睡眠   隐藏 模式二
                    cellTwo.viewStatusTwo.hidden = YES;//模式二 隐藏
                    if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                    {//睡眠时间长度时候大于5小时 并且梦境控制开启
                        cellTwo.sleepView.hidden = NO;// 模式一 打开
                        cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_ON;//梦境控制开启
                        cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                    }
                    else
                    {// 睡眠时长小于5小时 或者 梦境控制关闭
                        cellTwo.sleepView.hidden = YES;//模式一 隐藏
                    }
                }
                else
                {//如果是 前一个阶段是 1   深度睡眠
                    if (self.sleepGaishan == YES)
                    {//睡眠改善开启
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {//还需要判断当前时间长度时候大于5小时
                            cellTwo.sleepView.hidden = NO;// 模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_ON;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                            
                            cellTwo.viewStatusTwo.hidden = NO;//模式二 打开
                            cellTwo.labelTitleStatusTwo.text = REPORT_ONE_ALTERTION_OFF;// 显示 睡眠改善关闭
                            cellTwo.imageViewBackGroundTwo.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 report - one 灰色背景
                        }
                        else
                        {
                            cellTwo.viewStatusTwo.hidden = YES;//模式二 隐藏
                            cellTwo.sleepView.hidden = NO;// 模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_OFF;//  睡眠改善关闭
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 report - one 灰色背景
                        }
                    }
                    else
                    {//睡眠改善关闭
                        cellTwo.viewStatusTwo.hidden = YES;//隐藏 模式二
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {//还需要判断当前时间长度时候大于5小时
                            cellTwo.sleepView.hidden = NO;// 模式一 开启
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_ON;//显示 梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - two"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {
                            cellTwo.sleepView.hidden = YES;//模式一 隐藏
                        }
                    }
                }
                return cellTwo;
            }
                break;
            case 5:
            {//清醒状态
                [_sleepStyleArr addObject:@"200"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_FIVE];
                cellTwo.assessView.hidden = YES;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"清醒时长 %d小时%.1f分",hour,floatMin];
                cellTwo.oneXiala.hidden = NO;
                
                //计算进入睡眠的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 4 && priData != 1)
                {//如果前一个不是 1 和不是4   隐藏 模式二和模式一
                    cellTwo.viewStatusTwo.hidden = YES;  //模式二 隐藏
                    cellTwo.sleepView.hidden = YES;  // 模式一 隐藏
                }
                else
                {//模式二 隐藏
                    cellTwo.viewStatusTwo.hidden = YES; // 模式二 隐藏
                    if (priData == 1)
                    {// 如果前一个是 深度睡眠
                        if (self.sleepGaishan)
                        {// 如果睡眠改善开启
                            cellTwo.sleepView.hidden = NO; //模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果睡眠改善关闭
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else if (priData == 4)
                    {// 如果前一个是 做梦
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {// 如果梦境控制开启  并且 睡眠时间在5个小时以上
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果不符合 梦境控制开启， 或者不符合睡眠时间长度大于5小时以上的，需要隐藏 模式一
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else
                    {//其他错误  模式一 隐藏
                        cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                    }
                }
                return cellTwo;
            }
                break;
            case 6:
            {//接触不良 算时间
                [_sleepStyleArr addObject:@"0"];
                NSString *currenTime = self.hourMinuteArray[indexPath.row];//获取时刻
                cellTwo.reportTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[TJJDefines stringTimeDouble:currenTime],REPORT_SIX];
                cellTwo.assessView.hidden = YES;
                cellTwo.twoXialaImage.hidden = NO;
                cellTwo.sleepTime.hidden = NO;
                
                NSNumber *myNumber =  self.timerConvert[indexPath.row+1];//时长
                int timeNumber = [myNumber intValue];
                int hour = timeNumber*30/3600;
                float floatMin =  (timeNumber%120)/2.0;
                cellTwo.sleepTime.text = [NSString stringWithFormat:@"接触不良时长 %d小时%.1f分",hour,floatMin];
                cellTwo.oneXiala.hidden = NO;
                //计算进入睡眠的时间长度
                NSInteger sumOfState = 0;
                for (int i = 1; i < indexPath.row; i++)
                {
                    NSNumber *numberTemp =  self.timerConvert[i];
                    sumOfState += [numberTemp integerValue];//计算睡眠时间长度
                }
                int priData = [self.convert[indexPath.row] intValue];//取得前一个阶段的状态（如果是1的，则需要）
                if (priData != 4 && priData != 1)
                {//如果前一个不是 1 和不是4   隐藏 模式二和模式一
                    cellTwo.viewStatusTwo.hidden = YES;  //模式二 隐藏
                    cellTwo.sleepView.hidden = YES;  // 模式一 隐藏
                }
                else
                {//模式二 隐藏
                    cellTwo.viewStatusTwo.hidden = YES; // 模式二 隐藏
                    if (priData == 1)
                    {// 如果前一个是 深度睡眠
                        if (self.sleepGaishan)
                        {// 如果睡眠改善开启
                            cellTwo.sleepView.hidden = NO; //模式一 打开
                            cellTwo.sleepLabel.text = REPORT_ONE_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果睡眠改善关闭
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else if (priData == 4)
                    {// 如果前一个是 做梦
                        if (self.dreamKongZhi && sumOfState >= LENGTH_SLEEPSTATE)
                        {// 如果梦境控制开启  并且 睡眠时间在5个小时以上
                            cellTwo.sleepView.hidden = NO;//模式一 打开
                            cellTwo.sleepLabel.text = REPORT_FOUR_ALTERTION_OFF;//梦境控制开启
                            cellTwo.sleepBackGround.image = [UIImage imageNamed:@"report - one"];//report - two  绿色背景 eport - one 灰色背景
                        }
                        else
                        {// 如果不符合 梦境控制开启， 或者不符合睡眠时间长度大于5小时以上的，需要隐藏 模式一
                            cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                        }
                    }
                    else
                    {//其他错误  模式一 隐藏
                        cellTwo.sleepView.hidden = YES;// 模式一 隐藏
                    }
                }
                return cellTwo;
            }
                break;
                
            default:
                break;
        }
        
    }
    
    return nil;
}

//#pragma mark - 返回索引(数据源方法系统自动调用)
//- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
//{
//}
//
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//{
//
//}
#pragma mark -
#pragma mark 分享按钮
- (IBAction)shareClick
{
    //传的参数
    UserConfig *config =[UserConfig sharingUserConfig];
    NSDictionary *dic= @{@"Token":[config getToken]};
    AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
    httpManager.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
    httpManager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    //地址
    [httpManager POST:HOME_SHARE parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *retDic = [NetworkTool toNSDictionary:responseObject];
        NSDictionary *Dic = [NetworkTool parseJSONStringToNSDictionary:retDic[@"b"]];
        if ([retDic[@"a"] intValue] == 1) {
            [UMSocialData defaultData].extConfig.qqData.url = Dic[@"connect"];
            [UMSocialData defaultData].extConfig.wechatSessionData.url = Dic[@"connect"];
            [UMSocialData defaultData].extConfig.sinaData.urlResource.url = Dic[@"connect"];
            [UMSocialSnsService presentSnsIconSheetView:self
                                                 appKey:UMKEY
                                              shareText:Dic[@"describe"]
                                             shareImage:[UIImage imageNamed:@"icon.png"]
                                        shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                               delegate:nil];
        }else if ([retDic[@"a"] intValue] == 0) {
            NSLog(@"00000000000");
        }else if([retDic[@"a"] intValue] == -1){
            NSLog(@"-11111111");
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        TJJALERT_VIEW(ERROR_NETWORKINFO);
    }];
}

#pragma mark -
#pragma mark 导航返回按钮
- (IBAction)backClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -
#pragma mark viewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
